package com.ds.mq.consumer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @class: KafkaConsumer
 * @description:
 * @author: fs
 * @create: 2024/5/27 14:47
 **/
@Component
@Slf4j
@RequiredArgsConstructor
public class KafkaConsumer {


    //@KafkaListener(id = "consumer", topicPartitions = {@TopicPartition(topic = "loginout", partitions = {"0", "1", "2"})})
    //public void listen(ConsumerRecord<?, ?> record) {
    //    log.info("消费者key: " + record.key());
    //    log.info("消费者value: " + record.value());
    //    log.info("消费者headers: " + record.headers());
    //}

    @KafkaListener(topics = "loginout", containerFactory = "factory")
    public void listen(List<String> value, Acknowledgment acknowledgment) {
        log.info("消费者value: " + value.size());
        value.forEach(log::info);
        //acknowledgment.acknowledge();
    }


}
